﻿package mortal.game.net.command.copy.defenseCopy
{
    import Framework.MQ.*;
    import Message.Command.*;
    import Message.Public.*;
    import extend.language.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.net.broadCast.*;
    import mortal.game.scene3D.display3d.text3d.staticText3d.*;
    import mortal.game.scene3D.display3d.text3d.staticText3d.action.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.game.view.common.cd.*;
    import mortal.game.view.copy.defenseCopy.*;
    import mortal.mvc.core.*;

    public class DefenseCopyCommand extends BroadCastCall
    {

        public function DefenseCopyCommand(param1:Object)
        {
            super(param1);
            return;
        }// end function

        override public function call(param1:MessageBlock) : void
        {
            var _loc_2:DefenseCopyCache = null;
            var _loc_3:SDefenseCopyResult = null;
            var _loc_4:SDefenseCopyInfo = null;
            var _loc_5:SDefenseCopyReward = null;
            var _loc_6:SeqDefenseCopyBuyItemsMsg = null;
            var _loc_7:SSeqAttributeUpdate = null;
            var _loc_8:SDefenseCopyBuyItemMsg = null;
            var _loc_9:SPublicDictIntDt = null;
            var _loc_10:CDCache = null;
            var _loc_11:ICDData = null;
            var _loc_12:SMustDropItemMsg = null;
            var _loc_13:SSeqAttributeUpdate = null;
            var _loc_14:int = 0;
            var _loc_15:String = null;
            var _loc_16:Number = NaN;
            super.call(param1);
            _loc_2 = _cache.copy.defenseCopy;
            switch(param1.messageHead.command)
            {
                case EPublicCommand._ECmdPublicEndDefenseCopy:
                {
                    _loc_3 = param1.messageBase as SDefenseCopyResult;
                    _loc_2.isCopyEnd = true;
                    _loc_2.resultInfo = _loc_3;
                    NetDispatcher.dispatchCmd(ServerCommand.DefenseCopyEnd, _loc_3.result);
                    break;
                }
                case EPublicCommand._ECmdPublicDefenseInfo:
                {
                    _loc_4 = param1.messageBase as SDefenseCopyInfo;
                    _loc_2.copyInfo = _loc_4;
                    NetDispatcher.dispatchCmd(ServerCommand.DefenseCopyInfoUpdate, null);
                    break;
                }
                case EPublicCommand._ECmdPublicDefenseCopyReward:
                {
                    _loc_5 = param1.messageBase as SDefenseCopyReward;
                    _loc_2.copyReward = _loc_5;
                    NetDispatcher.dispatchCmd(ServerCommand.DefenseCopyRewardUpdate, null);
                    break;
                }
                case EPublicCommand._ECmdPublicDefenseCopyItemBuy:
                {
                    _loc_6 = param1.messageBase as SeqDefenseCopyBuyItemsMsg;
                    _loc_2.copyShopBuyItems = null;
                    _loc_2.copyShopBuyItems = _loc_6.buyItems;
                    NetDispatcher.dispatchCmd(ServerCommand.DefenseCopyShopUpdate, null);
                    break;
                }
                case EPublicCommand._ECmdPublicDefenseCopyAttrsUpdate:
                {
                    _loc_7 = param1.messageBase as SSeqAttributeUpdate;
                    this.updateAttrs(_loc_7);
                    NetDispatcher.dispatchCmd(ServerCommand.DefenseCopyRewardUpdate, null);
                    break;
                }
                case EPublicCommand._ECmdPublicDefenseCopyItemBuyUpdate:
                {
                    _loc_8 = param1.messageBase as SDefenseCopyBuyItemMsg;
                    _loc_14 = 0;
                    while (_loc_14 < _loc_2.copyShopBuyItems.length)
                    {
                        
                        if (_loc_2.copyShopBuyItems[_loc_14].itemCode == _loc_8.item.itemCode)
                        {
                            _loc_2.copyShopBuyItems[_loc_14].amount = _loc_8.item.amount;
                            break;
                        }
                        _loc_14++;
                    }
                    if (_loc_14 == _loc_2.copyShopBuyItems.length)
                    {
                        _loc_2.copyShopBuyItems.push(_loc_8.item);
                    }
                    NetDispatcher.dispatchCmd(ServerCommand.DefenseCopyShopUpdate, null);
                    break;
                }
                case EPublicCommand._ECmdPublicDefenseCopySkillCd:
                {
                    _loc_9 = param1.messageBase as SPublicDictIntDt;
                    _loc_10 = Cache.instance.cd;
                    for (_loc_15 in _loc_9.publicDictIntDt)
                    {
                        
                        _loc_11 = _loc_10.registerCDData(CDDataType.skillSeries, _loc_15);
                        _loc_16 = _loc_9.publicDictIntDt[_loc_15].time - ClockManager.instance.nowDate.time;
                        _loc_11.totalTime = _loc_16;
                        if (_loc_16 > 0)
                        {
                            _loc_11.startCoolDown();
                        }
                    }
                    NetDispatcher.dispatchCmd(ServerCommand.DefenseCopyRoleEquipUpdate, null);
                    break;
                }
                case EPublicCommand._ECmdPublicDefenseCopyMustDrop:
                {
                    _loc_12 = param1.messageBase as SMustDropItemMsg;
                    _loc_2.dropItemMsg = _loc_12;
                    NetDispatcher.dispatchCmd(ServerCommand.DefenseCopyInfoUpdate, null);
                    break;
                }
                case EPublicCommand._ECmdPublicDefenseGoldStuffLifeUpdate:
                {
                    _loc_13 = param1.messageBase as SSeqAttributeUpdate;
                    _loc_2.szBlood = _loc_13;
                    NetDispatcher.dispatchCmd(ServerCommand.DefenseCopyStuffLiftUpdate, null);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function updateAttrs(param1:SSeqAttributeUpdate) : void
        {
            var _loc_4:String = null;
            var _loc_5:Boolean = false;
            var _loc_7:SAttributeUpdate = null;
            var _loc_8:Boolean = false;
            var _loc_2:* = _cache.copy.defenseCopy;
            var _loc_3:* = new ActionVo();
            _loc_3.reInit(2, 0, 0, 0, 0, false, false);
            if (_loc_2 == null || _loc_2.copyReward == null)
            {
                _loc_5 = true;
            }
            var _loc_6:int = 0;
            while (_loc_6 < param1.updates.length)
            {
                
                _loc_7 = param1.updates[_loc_6];
                switch(_loc_7.attribute.value())
                {
                    case EEntityAttribute._EAttributeDefenseCopyCoinAdd:
                    {
                        if (!_loc_5)
                        {
                            _loc_2.copyReward.coin = _loc_2.copyReward.coin + _loc_7.value;
                        }
                        break;
                    }
                    case EEntityAttribute._EAttributeDefenseCopyBindGoldAdd:
                    {
                        if (!_loc_5)
                        {
                            _loc_2.copyReward.bindGold = _loc_2.copyReward.bindGold + _loc_7.value;
                        }
                        break;
                    }
                    case EEntityAttribute._EAttributeDefenseCopyBindCoinAdd:
                    {
                        if (!_loc_5)
                        {
                            _loc_2.copyReward.bindCoin = _loc_2.copyReward.bindCoin + _loc_7.value;
                        }
                        break;
                    }
                    case EEntityAttribute._EAttributeDefenseCopyExperienceAdd:
                    {
                        if (!_loc_5)
                        {
                            _loc_2.copyReward.experience = _loc_2.copyReward.experience + _loc_7.value;
                        }
                        break;
                    }
                    case EEntityAttribute._EAttributeDefenseCopyEquipPointAdd:
                    {
                        if (!_loc_5)
                        {
                            _loc_2.copyReward.equipPoint = _loc_2.copyReward.equipPoint + _loc_7.value;
                            if (_loc_7.value > 0)
                            {
                                _loc_8 = RolePlayer.hasInstacne() && RolePlayer.instance.bodyPlayer;
                                if (_loc_8)
                                {
                                    _loc_4 = Language.getStringByParam(20495, _loc_7.value);
                                    SText3DFactory.instance.createtext3D(_loc_4, 0, RolePlayer.instance.bodyPlayer, _loc_3);
                                }
                            }
                        }
                        break;
                    }
                    case EEntityAttribute._EAttributeDefenseCopyEquipPointDel:
                    {
                        if (!_loc_5)
                        {
                            _loc_2.copyReward.equipPoint = _loc_2.copyReward.equipPoint - _loc_7.value;
                        }
                        break;
                    }
                    case EEntityAttribute._EAttributeDropIcePiece:
                    {
                        _loc_4 = Language.getStringByParam(20496, _loc_7.value);
                        SText3DFactory.instance.createtext3D(_loc_4, 0, RolePlayer.instance.bodyPlayer, _loc_3);
                        break;
                    }
                    case EEntityAttribute._EAttributeDropStonePiece:
                    {
                        _loc_4 = Language.getStringByParam(20497, _loc_7.value);
                        SText3DFactory.instance.createtext3D(_loc_4, 0, RolePlayer.instance.bodyPlayer, _loc_3);
                        break;
                    }
                    case EEntityAttribute._EAttributeDropArrowPiece:
                    {
                        _loc_4 = Language.getStringByParam(20498, _loc_7.value);
                        SText3DFactory.instance.createtext3D(_loc_4, 0, RolePlayer.instance.bodyPlayer, _loc_3);
                        break;
                    }
                    case EEntityAttribute._EAttributeDropMagicPiece:
                    {
                        _loc_4 = Language.getStringByParam(20499, _loc_7.value);
                        SText3DFactory.instance.createtext3D(_loc_4, 0, RolePlayer.instance.bodyPlayer, _loc_3);
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
                _loc_6++;
            }
            return;
        }// end function

    }
}
